package com.guchenbo.lssp.domain;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
 * @author guchenbo
 */
public class LivySchemaField {
    private String name;
    /*
    一般的类型都是简单类型，比如数字、字符、日期，但是 PostgreSQL数据库还有数组类型
    数组类型livy会返回
    {
        "type": "array",
        "elementType": "string",
        "containsNull": true
    }
     */
    private JsonNode type;
    private Boolean nullable;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getNullable() {
        return nullable;
    }

    public void setNullable(Boolean nullable) {
        this.nullable = nullable;
    }

    public JsonNode getType() {
        return type;
    }

    public void setType(JsonNode type) {
        this.type = type;
    }

    public String wrapType() {
        JsonNode jsonNode = type;
        if (type instanceof ObjectNode) {
            ObjectNode jsonNodes = (ObjectNode) type;
            jsonNode = jsonNodes.get("type");
        }
        if (jsonNode == null) {
            return null;
        }
        return jsonNode.textValue();
    }
}
